﻿using System;
using SFML.Graphics;
using Transformable_Engine_v2.Engine.GameObjects.Containers;
using Transformable_Engine_v2.Engine.Global;
using Transformable_Engine_v2.Engine.Rendering;
using Transformable_Engine_v2.Engine.Transformable_Math.Geometry;
using Color = Transformable_Engine_v2.Engine.Graphics.Color;

namespace Transformable_Engine_v2.Engine.GameObjects.Primitives
{
    public class TextPrimitive : Container
    {
        private readonly SFML.Graphics.Text _text;

        public string Text
        {
            set { _text.DisplayedString = value; }
        }

        public Styles Style
        {
            set { _text.Style = (SFML.Graphics.Text.Styles)value; }
        }

        public uint CharacterSize
        {
            set { _text.CharacterSize = value; }
        }

        public override TE_Vector2 AbsolutePosition
        {
            protected set
            {
                base.AbsolutePosition = value;
                if(_text != null)
                _text.Position = AbsolutePosition.ToVector2f();
            }
        }

        public string Font
        {
            set
            {
                _text.Font = new Font(value);
            }
        }

        public Color Color
        {
            set
            {
                _text.Color = value.ToSFMLColor();
            }
        }

        [Flags]
        public enum Styles
        {
            Regular = 0,
            Bold = 1,
            Italic = 2,
            Underlined = 4,
        }

        public TextPrimitive()
        {
            _text = new SFML.Graphics.Text();
        }

        public override void Draw()
        {
            if (Visible)
            {
                if (ShaderHandler.HasShader)
                    RenderTargetHandler.GetCurrentRenderTarget().Draw(_text, ShaderHandler.CurrentShader);
                else
                    RenderTargetHandler.GetCurrentRenderTarget().Draw(_text);
            }
        }
    }
}